// components/personal-info.ts
import { validateNull } from '../../utils/util';
import userBaseInfoState from '../../stores/userBaseInfo'

import {getPatientBaseObject} from '../../utils/api/patientBase'

Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    user: <PatientBaseEntity> {
      patientName: '张三',
      birthday: '1990-01-01',
      phoneNumber: '12312',
      sex: '男性',
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取用户基本信息
    getUserInfo() {
      const data = <PatientBaseEntity>{ wxUid: wx.getStorageSync("openid") };
      getPatientBaseObject(data).then((res: any) => {
        console.log('获取基本信息成功', res);
        userBaseInfoState.onChangeData(res.data[0])
        this.setData({
          user: userBaseInfoState.data
        })
      }).catch((err: any) => {
        console.log("获取基本信息失败",err);
      })
    }
  },

  lifetimes: {
    // 视图层布局完成后执行
    ready: function() {
      userBaseInfoState.bind(this, '$userBase');
      this.getUserInfo();
    },
  },
  pageLifetimes: {
    show: function () { 
      this.getUserInfo();
    },
  }
})